home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 409_01 / paranoid.c < prev    next >
C/C++ Source or Header  |  1993-10-21  |  24KB  |  852 lines

  1. /****************************************************************************
  2. *
  3. *                  Paranoid - VESA VBE stress test program
  4. *
  5. *                   Copyright (C) 1993 SciTech Software.
  6. *                           All rights reserved.
  7. *
  8. * Filename:     $RCSfile: paranoid.c $
  9. * Version:      $Revision: 1.1 $
  10. *
  11. * Language:     ANSI C
  12. * Environment:  IBM PC (MS DOS)
  13. *
  14. * Description:    Paranoid test program. This program is designed to stress
  15. *                test a VESA VBE implementation, and check it for full
  16. *                conformance with the VBE standard that it claims to conform
  17. *                to (supports only standards >= 1.2 standard).
  18. *
  19. *                This program uses the SuperVGA test kit to perform all
  20. *                graphics output when testing the appropriate video modes
  21. *                for conformance (and thus only works on 386 and above
  22. *                machines).
  23. *
  24. *               MUST be compiled in the large memory model.
  25. *
  26. *                This program is freely distributable in the executable
  27. *                form. The source code is under the same restrictions as
  28. *                the SuperVGA kit it belong in.
  29. *
  30. * $Id: paranoid.c 1.1 1993/10/22 08:59:44 kjb release $
  31. *
  32. ****************************************************************************/
  33.  
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <stdarg.h>
  37. #include <dos.h>
  38. #include <string.h>
  39. #include <conio.h>
  40. #include "svga.h"
  41. #include "vesavbe.h"
  42.  
  43. /*----------------------------- Implementation ----------------------------*/
  44.  
  45. typedef struct {
  46.     int        ax,bx,cx,dx,si,di,es,ds;
  47.     } regs;
  48.  
  49. FILE    *logfile = NULL;
  50. int        CP_x,CP_y,VBEVersion,maxbanks,VBEFunc = 0,numErrors = 0;
  51. bool    failed = false;
  52. short    modelist[100];
  53. char    *signon =    "Paranoid v1.0 - VESA VBE stress test program\n"
  54.                     "                Copyright (C) 1993 SciTech Software\n\n";
  55.  
  56. /* Table of memory model names */
  57.  
  58. char *memModelNames[] = {
  59.     "Text Mode",
  60.     "CGA Graphics",
  61.     "Hercules Graphics",
  62.     "4-plane planar",
  63.     "Packed Pixel",
  64.     "Non-chain 4, 256 color",
  65.     "Direct Color RGB",
  66.     "Direct Color YUV",
  67.     };
  68.  
  69. int queryCpu(void);
  70.  
  71. void out(const char *fmt, ... )
  72. {
  73.     va_list argptr;
  74.  
  75.     va_start(argptr, fmt);
  76.     vfprintf(stdout, fmt, argptr);
  77.     vfprintf(logfile, fmt, argptr);
  78.     va_end(argptr);
  79. }
  80.  
  81. void log(const char *fmt, ... )
  82. {
  83.     va_list argptr;
  84.  
  85.     va_start(argptr, fmt);
  86.     vfprintf(logfile, fmt, argptr);
  87.     va_end(argptr);
  88. }
  89.  
  90. /* Routine to convert the input value to its binary representation */
  91.  
  92. char *binary(unsigned value)
  93. {
  94.     static char    buf[11] = "00000000b";
  95.     unsigned    mask = 0x80;
  96.     int         i;
  97.  
  98.     for (i = 0; i < 8; i++) {
  99.         buf[i] = value & mask ? '1' : '0';
  100.         mask >>= 1;
  101.         }
  102.  
  103.     return buf;
  104. }
  105.  
  106. void startCheck(int _VBEFunc)
  107. /****************************************************************************
  108. *
  109. * Function:        startCheck
  110. * Parameters:    _VBEFunc    - VBE Function number we are currently checking
  111. *
  112. * Description:    Begins the logging of errors for this function.
  113. *
  114. ****************************************************************************/
  115. {
  116.     log("Checking function %02Xh ... ", VBEFunc = _VBEFunc);
  117.     numErrors = 0;
  118. }
  119.  
  120. void endCheck(void)
  121. /****************************************************************************
  122. *
  123. * Function:        endCheck
  124. *
  125. * Description:    Ends the checking of a particular VBE function.
  126. *
  127. ****************************************************************************/
  128. {
  129.     if (numErrors == 0)
  130.         log("Passed.\n");
  131.     else
  132.         log("\n%d errors logged for function %02Xh.\n", numErrors, VBEFunc);
  133. }
  134.  
  135. void fail(const char *msg, ... )
  136. /****************************************************************************
  137. *
  138. * Function:        fail
  139. * Parameters:    msg    - Message describing error
  140. *
  141. * Description:    Logs a failure message to the log file outlining the problem
  142. *                that was encountered.
  143. *
  144. ****************************************************************************/
  145. {
  146.     va_list argptr;
  147.  
  148.     if (numErrors == 0)
  149.         log("\n\n");
  150.     numErrors++;
  151.     failed = true;
  152.  
  153.     va_start(argptr, msg);
  154.     fprintf(logfile,"    ");
  155.     vfprintf(logfile, msg, argptr);
  156.     va_end(argptr);
  157. }
  158.  
  159. bool callVBE(regs *r)
  160. /****************************************************************************
  161. *
  162. * Function:        callVBE
  163. * Parameters:    r    - Structure holding register values to load
  164. * Returns:        True if successful, false if function failed
  165. *
  166. * Description:    Loads the appropriate registers with the values from
  167. *                the register structure and executes and int 10h to call
  168. *                the VBE. It checks to ensure that register values are
  169. *                preserved across all calls correctly and ensures that the
  170. *               function executed successfully.
  171. *
  172. ****************************************************************************/
  173. {
  174.     union REGS        rg;
  175.     struct SREGS    sr;
  176.     int                mask;
  177.  
  178.     rg.x.ax = r->ax;    rg.x.bx = r->bx;
  179.     rg.x.cx = r->cx;    rg.x.dx = r->dx;
  180.     rg.x.si = r->si;    rg.x.di = r->di;
  181.     sr.es = r->es;        sr.ds = r->ds;
  182.     int86x(0x10,&rg,&rg,&sr);
  183.  
  184.     /* Check to ensure all register are preserved across call. We define
  185.      * the mask to be a one for a register that must be preserved, and
  186.      * a zero for a register that can change. AX is always the result
  187.      * code, so this leave 7 bits to represent each register.
  188.      */
  189.  
  190.     switch (r->ax & 0xFF) {
  191.         case 0x00:    mask = 0x7F;    break;
  192.         case 0x01:    mask = 0x7F;    break;
  193.         case 0x02:    mask = 0x7F;    break;
  194.         case 0x03:    mask = 0x7E;    break;
  195.         case 0x04:    if ((r->dx & 0xFF) == 0)
  196.                         mask = 0x7E;        /* State size call        */
  197.                     else mask = 0x7F;        /* Other calls            */
  198.                     break;
  199.         case 0x05:    if ((r->bx >> 8) == 0)
  200.                         mask = 0x7F;        /* Set window call        */
  201.                     else mask = 0x7B;        /* Get window call        */
  202.                     break;
  203.         case 0x06:    mask = 0x78;    break;
  204.         case 0x07:    if (r->bx == 0)
  205.                         mask = 0x7F;        /* Set display start    */
  206.                     else mask = 0x78;        /* Get display start    */
  207.                     break;
  208.         case 0x08:    mask = 0x7E;    break;
  209.         default:    mask = 0;
  210.         }
  211.  
  212.     if ((mask & 0x01) && (r->bx != rg.x.bx))
  213.         fail("Function %02Xh failed to preserve BX\n", r->ax & 0xFF);
  214.     if ((mask & 0x02) && (r->cx != rg.x.cx))
  215.         fail("Function %02Xh failed to preserve CX\n", r->ax & 0xFF);
  216.     if ((mask & 0x04) && (r->dx != rg.x.dx))
  217.         fail("Function %02Xh failed to preserve DX\n", r->ax & 0xFF);
  218.     if (r->si != rg.x.si)
  219.         fail("Function %02Xh failed to preserve SI\n", r->ax & 0xFF);
  220.     if (r->di != rg.x.di)
  221.         fail("Function %02Xh failed to preserve DI\n", r->ax & 0xFF);
  222.     if (r->ds != sr.ds)
  223.         fail("Function %02Xh failed to preserve DS\n", r->ax & 0xFF);
  224.     if (r->es != sr.es)
  225.         fail("Function %02Xh failed to preserve ES\n", r->ax & 0xFF);
  226.  
  227.     r->ax = rg.x.ax;    r->bx = rg.x.bx;
  228.     r->cx = rg.x.cx;    r->dx = rg.x.dx;
  229.     r->si = rg.x.si;    r->di = rg.x.di;
  230.     r->es = sr.es;        r->ds = sr.ds;
  231.  
  232.     return (r->ax == 0x004F);
  233. }
  234.  
  235. void checkFunction00h(void)
  236. /****************************************************************************
  237. *
  238. * Function:        checkFunction00h
  239. *
  240. * Description:    Calls function 00h to determine if a VESA VBE is present,
  241. *                and check it for conformance.
  242. *
  243. ****************************************************************************/
  244. {
  245.     VgaInfoBlock    vgaInfo;
  246.     regs            r;
  247.     short            i,*modes;
  248.  
  249.     r.es = SEG(&vgaInfo);
  250.     r.di = OFF(&vgaInfo);
  251.     r.ax = 0x4F00;
  252.     if (callVBE(&r)) {
  253.         if (vgaInfo.VESAVersion < 0x102) {
  254.             out("Detected a VBE %d.%d interface. This program only checks interfaces that\n",
  255.                 vgaInfo.VESAVersion >> 0x8,vgaInfo.VESAVersion & 0xF);
  256.             out("conform to the VBE 1.2 or later specifications.\n");
  257.             exit(1);
  258.             }
  259.  
  260.         printf("VBE %d.%d Interface detected - checking for conformance\n\n",
  261.             vgaInfo.VESAVersion >> 0x8,vgaInfo.VESAVersion & 0xF);
  262.  
  263.         log("VBE Version:  %d.%d\n",vgaInfo.VESAVersion >> 0x8,
  264.             vgaInfo.VESAVersion & 0xF);
  265.         log("OEMString:    %s\n",vgaInfo.OEMStringPtr);
  266.         log("Capabilities: %s (%04Xh)\n",binary(vgaInfo.Capabilities),
  267.             vgaInfo.Capabilities);
  268.         log("Total Memory: %d Kb\n",memory = vgaInfo.TotalMemory * 64);
  269.         log("\nAvailable Modes:\n\n");
  270.  
  271.         modes = vgaInfo.VideoModePtr;
  272.         i = 0;
  273.         while (*modes != -1) {
  274.             modelist[i] = *modes;
  275.             log("%04Xh ",*modes++);
  276.             if ((++i % 10) == 0)
  277.                 log("\n");
  278.             }
  279.         modelist[i] = -1;
  280.         log("\n\n");
  281.         startCheck(0x00);
  282.